import axios from 'axios'//引入axios进行二次封装

let service = axios.create({
    timeout:10*1000,
    baseURL:'/api' //基本路径
})
service.interceptors.request.use((config)=>{
    return config;
},(error)=>{
    return Promise.reject(error);
})
service.interceptors.response.use((res)=>{
    return res
},(error)=>{
    if( error.response.status == 401 ){
        Toast.fail({ message: "身份认证失败,登陆过期,请重新登录!" })
        this.$router.push("/login");
    }
    else if( error.response.status == 404 ){
        Toast.fail({ message: "访问路径有误!" })
    }
    else if( error.response.status == 500 ){
        Toast.fail({ message: "服务器内部错误!" })
    }
    return Promise.reject(error);
})
export default service